     <!-- BOX 3 -->
   	<script type="text/javascript">
			<?php
			//Variaveis para configuracao da GRID
			//$gridName - ID da GRID
			//$controller - Controlador da GRID
			//$titleList - Titulo da GRID
			//$titleForm - Titulo do Formulario
			$gridName = "gridContatos";
			$controller = "contatos";
			$titleList = "Lista de Contatos";
			?>
			//Array com todos os campos da tabela.
			var arr_fields = [
			                  {nome:'id_contato',label:'Id', tp_obj: 'hid', tipo : 'str', grid:{name:'id_contato',index:'tb_contatos.id_contato', width:15, def_order:true,order:'asc'}},
			                  {nome:'nome',label:'Nome', tp_obj: 'txt', tipo : 'str', grid:{name:'nome',index:'tb_contatos.nome', width:80, def_order:false,order:''}},
			                  {nome:'nome_fantasia',label:'Conta', tp_obj: 'txt', tipo : 'str', grid:{name:'nome_fantasia',index:'tb_contas.nome_fantasia', width:100, def_order:false,order:''}},
			                  {nome:'telefone',label:'Telefone', tp_obj: 'txt', tipo : 'str', grid:{name:'telefone',index:'tb_contatos.telefone', width:40, def_order:false,order:''}}
				              	];

			//Variavel com o codigo da linha selecionada
			var editValue = null;
			$(document).ready(function(){
				var arr_fld_grid = new Array();
				var arr_fld_labels = new Array();
				var fld_sort_name = "";
				var fld_sort_order = "";

				//Monta os arrays com os labels e os campos
				for(i=0; i<arr_fields.length; i++)
				{
					if(arr_fields[i].grid != null)
					{
						arr_fld_grid.push(arr_fields[i].grid);
						arr_fld_labels.push(arr_fields[i].label);
						if(arr_fields[i].grid.def_order)
						{
							fld_sort_name = arr_fields[i].grid.name;
							fld_sort_order = arr_fields[i].grid.order;
						}
					}
				}

				//Montagem da GRID
				jQuery("#<?php echo $gridName; ?>").jqGrid({
				   	url:'<?php echo base_url().$controller."/listAll"?>',
					datatype: "json",
				   	colNames:arr_fld_labels,
				   	colModel:arr_fld_grid,
				   	rowNum:15,
				   	rowList:[10,15,20,30],
				   	height: 'auto',
				   	width:'650',
				   	pager: '#p<?php echo $gridName; ?>',
				   	sortname: fld_sort_name,
				    viewrecords: true,
				    sortorder: fld_sort_order,
				    caption:'<?php echo $titleList; ?>',
				    onSelectRow: function(id){ 
						if(id && id!==editValue){ 
							editValue=id; 
						} 
					},
					multiselect: true
				})
				.navGrid('#p<?php echo $gridName; ?>',{edit:false,add:false,del:false,search:false,refresh:false})
			});

			$(document).ready(function() {
	            $("#bt_search").button({
		            icons: {primary: "searchIcon"}
	            }).click(function(){
					jQuery("#<?php echo $gridName; ?>").jqGrid('searchGrid',{multipleSearch:true});
	    		});

	            $("#bt_select").button({
		            icons: {primary: "selectIcon"}
	            }).click(function(){
	            	var contacts;
	            	contacts = jQuery("#<?php echo $gridName; ?>").jqGrid('getGridParam','selarrrow');
	            	if(contacts != "")
	            	{
	             		window.opener.setContactsContatos(contacts);
	             		window.close();
		            }
	            	else
	            	{
						dialogMessage('Selecione uma linha','dialog-message');   
						$("#<?php echo $gridName; ?>").trigger("reloadGrid");
		            }
	    		});

	            $("#bt_refresh").button({
		            icons: {primary: "refreshIcon"}
	            }).click(function(){
	            	$("#<?php echo $gridName; ?>").trigger("reloadGrid");
	    		});
	        });	    			
		</script> 
		<style>
        	#toolbar {
        		padding: 2px 4px;
				width:640px;
        	}
    	</style>
		<div align="center">
            <div id="toolbar" class="ui-widget-header ui-corner-all">
            	<table border="0" cellpadding="0" cellspacing="0" width="100%">
            		<tr>
            			<td align="left" width="13%">
            			&nbsp;
            			</td>
            			<td align="center" width="74%">
                        	<button id="bt_search">Pesquisar</button>
                        	<button id="bt_select">Selecionar</button>
            			</td>
            			<td align="right" width="13%">
                        	<button id="bt_refresh">Recarregar</button>
            			</td>
            		</tr>
            	</table>
            </div>
			<table id="<?php echo $gridName; ?>"></table>
			<div id="p<?php echo $gridName; ?>"></div>
		</div>    	
	</body>
</html>